package org.example.j2024_11_10;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;

@RestController
@RequestMapping("/header")
public class HeaderController {

    @ResponseBody
    @RequestMapping("/h1")
    public String h1(HttpServletResponse response){
        response.setStatus(200);
        return "设置状态码成功";
    }

    @RequestMapping(value = "/h2" , produces = "application/json")
    public String h2(){
        return "{ \"a\":1}";
    }

    @RequestMapping("/h3")
    public String h3(HttpServletResponse response){
      response.setHeader("myheader", "myvalue");
      return  "设置header成功";
    }


}
